package com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.bean;

import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.AddCategoryPropertyDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.EditCategoryPropertyDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.GetPropertyDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.SetCategoryPropertyNameIsShowDTO;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class CategoryPropertyNameBean {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.id
     *
     * @mbggenerated
     */
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.fk_category
     *
     * @mbggenerated
     */
    private String fkCategory;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.property_name
     *
     * @mbggenerated
     */
    private String propertyName;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.property_name_prompt
     *
     * 属性名称提示
     * @mbggenerated
     */
    private String propertyNamePrompt;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.is_required
     *
     * 是否必填属性
     * @mbggenerated
     */
    private Boolean isRequired;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.is_input
     *
     * 是否输入属性
     * @mbggenerated
     */
    private Boolean isInput;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.is_multi_select
     *
     * 是否可以多选
     * @mbggenerated
     */
    private Boolean isMultiSelect;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.is_show
     *
     * 是否显示属性
     * @mbggenerated
     */
    private Boolean isShow;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.add_time
     *
     * @mbggenerated
     */
    private Date addTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category_property_name.is_delete
     *
     * @mbggenerated
     */
    private Boolean isDelete;

    /**
     * 扩展字段.
     *
     * 表示当前属性所对应的属性值集合
     *
     * 此字段在数据库表中不存在.
     */
    public List<CategoryPropertyValueBean> propertyValueList;

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_category_property_name
     *
     * @mbggenerated
     */
    public CategoryPropertyNameBean(String id, String fkCategory, String propertyName, String propertyNamePrompt, Boolean isRequired, Boolean isInput, Boolean isMultiSelect, Boolean isShow, Date addTime, Boolean isDelete) {
        this.id = id;
        this.fkCategory = fkCategory;
        this.propertyName = propertyName;
        this.propertyNamePrompt = propertyNamePrompt;
        this.isRequired = isRequired;
        this.isInput = isInput;
        this.isMultiSelect = isMultiSelect;
        this.isShow = isShow;
        this.addTime = addTime;
        this.isDelete = isDelete;
    }

    public CategoryPropertyNameBean(){

    }


    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.id
     *
     * @return the value of tb_category_property_name.id
     *
     * @mbggenerated
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.fk_category
     *
     * @return the value of tb_category_property_name.fk_category
     *
     * @mbggenerated
     */
    public String getFkCategory() {
        return fkCategory;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.property_name
     *
     * @return the value of tb_category_property_name.property_name
     *
     * @mbggenerated
     */
    public String getPropertyName() {
        return propertyName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.property_name_prompt
     *
     * @return the value of tb_category_property_name.property_name_prompt
     *
     * @mbggenerated
     */
    public String getPropertyNamePrompt() {
        return propertyNamePrompt;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.is_required
     *
     * @return the value of tb_category_property_name.is_required
     *
     * @mbggenerated
     */
    public Boolean getIsRequired() {
        return isRequired;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.is_input
     *
     * @return the value of tb_category_property_name.is_input
     *
     * @mbggenerated
     */
    public Boolean getIsInput() {
        return isInput;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.is_multi_select
     *
     * @return the value of tb_category_property_name.is_multi_select
     *
     * @mbggenerated
     */
    public Boolean getIsMultiSelect() {
        return isMultiSelect;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.is_show
     *
     * @return the value of tb_category_property_name.is_show
     *
     * @mbggenerated
     */
    public Boolean getIsShow() {
        return isShow;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.add_time
     *
     * @return the value of tb_category_property_name.add_time
     *
     * @mbggenerated
     */
    public Date getAddTime() {
        return addTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category_property_name.is_delete
     *
     * @return the value of tb_category_property_name.is_delete
     *
     * @mbggenerated
     */
    public Boolean getIsDelete() {
        return isDelete;
    }

    @Override
    public String toString() {
        return "CategoryPropertyNameBean{" +
                "id='" + id + '\'' +
                ", fkCategory='" + fkCategory + '\'' +
                ", propertyName='" + propertyName + '\'' +
                ", propertyNamePrompt='" + propertyNamePrompt + '\'' +
                ", isRequired=" + isRequired +
                ", isInput=" + isInput +
                ", isMultiSelect=" + isMultiSelect +
                ", isShow=" + isShow +
                ", addTime=" + addTime +
                ", isDelete=" + isDelete +
                ", propertyValueList=" + propertyValueList +
                '}';
    }

    public static GetPropertyDTO toGetPropertyDTO(CategoryPropertyNameBean propertyNameBean) {
        GetPropertyDTO dto = new GetPropertyDTO();
        final String propertyNameId = propertyNameBean.id;
        dto.id = propertyNameId;
        dto.categoryId = propertyNameBean.fkCategory;
        dto.isInput = propertyNameBean.isInput;
        dto.isMultiSelect = propertyNameBean.isMultiSelect;
        dto.isRequired = propertyNameBean.isRequired;
        dto.isShow= propertyNameBean.isShow;
        dto.propertyName = propertyNameBean.propertyName;
        dto.propertyNamePrompt = propertyNameBean.propertyNamePrompt;

        //
        if (propertyNameBean.propertyValueList != null){
            dto.propertyValueList = propertyNameBean.propertyValueList.stream()
                    .map(valueBean -> {
                GetPropertyDTO.PropertyValue value = new GetPropertyDTO.PropertyValue();
                value.categoryPropertyNameId = propertyNameId;
                value.id = valueBean.getId();
                value.isShow = valueBean.getIsShow();
                value.propertyValue = valueBean.getPropertyValue();
                return value;
            }).collect(Collectors.toList());
        }
        return dto;
    }

    public static CategoryPropertyNameBean from(AddCategoryPropertyDTO dto) {
        CategoryPropertyNameBean bean = new CategoryPropertyNameBean();
        bean.addTime = new Date();
        bean.fkCategory = dto.categoryId;
        bean.isDelete = false;
        bean.isInput = dto.isInput;
        bean.isMultiSelect = dto.isMultiselect;
        bean.isRequired = dto.isRequied;
        bean.isShow = dto.isShow;
        bean.propertyName = dto.propertyName;
        bean.propertyNamePrompt = dto.propertyNamePrompt;
        return bean;
    }

    public static CategoryPropertyNameBean from(EditCategoryPropertyDTO dto) {
        CategoryPropertyNameBean bean = new CategoryPropertyNameBean();
        bean.id = dto.categoryPropertyNameId;
        bean.isShow = dto.isShow;
        bean.isInput = dto.isInput;
        bean.isMultiSelect = dto.isMultiSelect;
        bean.isRequired = dto.isRequired;
        bean.propertyName = dto.propertyName;
        bean.propertyNamePrompt = dto.propertyNamePrompt;
//        bean.fkCategory = dto.categoryId; // 属性所属的类目暂时不允许修改
        return bean;
    }

    public static CategoryPropertyNameBean from(SetCategoryPropertyNameIsShowDTO dto) {
        CategoryPropertyNameBean bean = new CategoryPropertyNameBean();
        bean.id = dto.categoryPropertyNameId;
        bean.isShow = dto.isShow;
        return bean;
    }
}